//
//  MainViewController.m
//  MainNavSearchAndSegmentDemo
//
//  Created by dihuijun on 17/5/26.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "MainViewController.h"
#import "MainTableHeaderView.h"
#define ScrollHeight 180
///选择器
#import "CycleSegmentViewController.h"
@interface MainViewController ()

/**   头部轮播图   */
@property (nonatomic, strong) MainTableHeaderView *headerView;


/**   选择控制器   */
@property (nonatomic, strong) CycleSegmentViewController *segmentController;
@end

static NSString *const ID = @"CellID";
@implementation MainViewController

/**   选择控制器   */
- (CycleSegmentViewController *)segmentController{
    if(!_segmentController){
        _segmentController = [[CycleSegmentViewController alloc]init];
        _segmentController.mainVC = self;
        _segmentController.view.backgroundColor = [UIColor whiteColor];
        _segmentController.view.frame = CGRectMake(0, ScrollHeight, screenW, screenH);
        
        __weak typeof(self) wself = self;
        _segmentController.yoffSetBlock = ^(CGFloat yoffSet){
            NSLog(@"%.2f",yoffSet);
            if(ABS(yoffSet)>180.0){
                [UIView animateWithDuration:0.75 animations:^{
                    wself.segmentController.view.y = 0;
//                    wself.segmentController.view.y = 0;
                }];
                
            }else{
                [UIView animateWithDuration:0.75 animations:^{
                     wself.segmentController.view.y = ScrollHeight;
                }];
               
            }
        };
        
    }
    return _segmentController;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"滚动";
    self.navigationController.navigationBar.translucent = NO;

    self.headerView = [[MainTableHeaderView alloc]initWithFrame:CGRectMake(0, 0, screenW, 180)];
    [self.view addSubview:self.headerView];
    self.headerView.tapblock = ^(NSInteger index){
        NSLog(@"点击了 : %zd",index);
    };
    
    ///2.segmentController
    [self.view addSubview:self.segmentController.view];
}










@end
